home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 001a / jmod310.zip / TEST.C < prev    next >
Text File  |  1991-11-30  |  11KB  |  298 lines

  1. /****************************************************************************/
  2. /*     These routines test the data-compression and expansion routines      */
  3. /*     To alter:                                                            */
  4. /*     MAKE TEST                                                            */
  5. /*     ( use the MAKE file )                                                */
  6. /*                                                                          */
  7. /*     When compiling, you will get 3 warning messages about unused         */
  8. /*     parameters. This is because of the dummy screen() routine which      */
  9. /*     does nothing except keep the linker happy.                           */
  10. /*                                                                          */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*     When executed, this program uses the timer-tick for data and tests   */
  14. /*     compression/expansion for all data lengths used.                     */
  15. /*     It takes about 84 hours to execute.  It aborts on the first error.   */
  16. /*                                                                          */
  17. /*     Since one might like to stop it to use their computer, I added       */
  18. /*     routines so it may be restarted with the last buffer size.           */
  19. /*                                                                          */
  20. /*     This routine thoroughly tests both the file I/O and the compression  */
  21. /*     expansion, CRC routines to verify that they will NOT corrupt any     */
  22. /*     data. These tests are exhaustive. They were used to find the         */
  23. /*     MicroSoft stream-I/O bug and are the reason I changed to the         */
  24. /*     Unix-type "handle" file routines.                                    */
  25. /*                                                                          */
  26. /*                                                                          */
  27. /****************************************************************************/
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>                     /* Used for _free()                 */
  31. #include <string.h>
  32. #if defined (TURBOC)
  33.     #include <alloc.h>
  34. #else
  35.     #include <malloc.h>
  36. #endif
  37. #include <time.h>
  38. #define SCREEN
  39. #include "jmodem.h"
  40.  
  41. byte far *tick = (byte far *) 0x46C;
  42. SYS syst;
  43. short main (void);
  44. char input[64];
  45. byte *in_buf;
  46. byte *out_buf;
  47. byte *cmp_buf;
  48. byte *sav_ptr;
  49. void show_hex(word, byte *);
  50. char file_name[]="JMODEM.$$$";
  51. word status;
  52. short handle;
  53.  
  54. short main()
  55. {
  56.     word i,j,k,l;
  57.     short flag = 1;
  58.     short max = DAT_MAX;
  59.     l =  DAT_MAX;
  60.     printf("\nBuffer size? (%d) ",DAT_MAX);
  61.     gets(input);
  62.     sscanf(input," %d",&l);
  63.     max = l;
  64.  
  65.     in_buf  = (byte *) malloc(l);                      /* Allocate buffer */
  66.     if (!in_buf)                                       /* If an error     */
  67.     {
  68.         printf("\nMemory error!");
  69.         return 1;
  70.     }
  71.     out_buf = (byte *) malloc(l);                       /* Allocate buffer */
  72.     if (!out_buf)                                       /* If an error     */
  73.     {
  74.         printf("\nMemory error!");
  75.         return 1;
  76.     }
  77.  
  78.     printf("Will write %d records.",l);
  79.     input[0] = 0x00;
  80.     while (input[0] != 'C' && input[0] != 'F')
  81.     {
  82.         printf("\nTest CRC and compressor or File I/O? (C/F) ");
  83.         gets(input);
  84.         input[0] = input[0] & (char)95;
  85.     }
  86.     switch (input[0])
  87.     {
  88.         case 'F':
  89.         {
  90.         printf("\nWant to check CRC / comp. after the file test? (Y/N) ");
  91.             gets(input);
  92.             if ( (input[0] & 95) == 'Y')
  93.                 flag = 0;
  94.             sav_ptr = out_buf;
  95.             for (i=0; i<l; i++)
  96.                 *out_buf++ = (byte) i;
  97.             out_buf = sav_ptr;
  98.             while (l)
  99.             {
  100.                 remove ("JMODEM.OLD");
  101.                 printf("\nOpening file %s for write.",file_name);
  102.                 status = file_io(CREATE, &handle, 
  103.                                          file_name, (byte *) 0x0000) ;
  104.                 if (status)
  105.                 {
  106.                     printf("\nOpen failed~!");
  107.                     return(1);
  108.                 }
  109.                 printf("\nWriting file %s",file_name);
  110.                 for (i=0; i<100; i++)
  111.                 {
  112.                     printf("\nRecord %d,",i);
  113.                     status = file_io( WRITE ,            /* Function        */
  114.                                  &handle,                /* File handle     */
  115.                                  out_buf,                /* Where data is   */
  116.                                  l );                    /* Amount to write */
  117.                     if (status != l)
  118.                     {
  119.                         printf(" only wrote %d bytes!",status);
  120.                         return 1;
  121.                     }
  122.                     printf(" %d bytes okay.",status);
  123.                  }
  124.                  printf("\nClosing file");
  125.                  file_io(CLOSE,                          /* Function        */
  126.                        &handle,                          /* Open handle     */
  127.                        file_name,                        /* Name not used   */
  128.                        (byte *) 0x0000);                 /* Buffer not used */
  129.  
  130.                 printf("\nOpening file %s for read.",file_name);
  131.                 status = file_io(OPEN_READ, &handle,
  132.                                             file_name,
  133.                                             (byte *) 0x0000);
  134.                 if (status)
  135.                 {
  136.                     printf("\nOpen failed~!");
  137.                     return(1);
  138.                 }
  139.  
  140.                 printf("\nReading file %s",file_name);
  141.                 for (i=0; i<100; i++)
  142.                 {
  143.                     printf("\nRecord %d,",i);
  144.                     status = file_io( READ ,             /* Function        */
  145.                                  &handle,                /* File handle     */
  146.                                  in_buf,                 /* Where data is   */
  147.                                  l );                    /* Amount to write */
  148.                     if (status != l)
  149.                     {
  150.                         printf(" only read %d bytes!",status);
  151.                         return 1;
  152.                     }
  153.                     printf(" %d bytes okay,",status);
  154.  
  155.                     printf(" comparing,");
  156.                     k = memicmp (out_buf, in_buf,l);
  157.                     if (k)
  158.                     {
  159.                         printf(" did not compare!");
  160.                         return(1);
  161.                     }
  162.                     printf(" okay.");
  163.  
  164.                  }
  165.                  printf("\nClosing file");
  166.                  file_io(CLOSE,                          /* Function        */
  167.                        &handle,                          /* Open handle     */
  168.                    file_name,                            /* Name not used   */
  169.                    (byte *) 0x0000);                     /* Buffer not used */
  170.             l--;
  171.             }
  172.             remove ("JMODEM.OLD");
  173.             remove ("JMODEM.$$$");
  174.             if (flag)
  175.                 return(0);
  176.         }
  177.         case 'C':
  178.         {
  179.             l = max;
  180.             cmp_buf = (byte *) malloc(DAT_LEN);          /* Allocate buffer */
  181.             if (!cmp_buf)                                /* In an error     */
  182.             {
  183.                 printf("\nMemory error!");
  184.                 return 1;
  185.             }
  186.             printf("\nFilling the input buffer with consecutive bytes.");
  187.             sav_ptr = in_buf;                           /* Save            */
  188.             for (i=0; i< l; i++)
  189.                 *in_buf++ = (byte) i;                   /* Fill the buffer */
  190.  
  191.             in_buf = sav_ptr;
  192.             printf("\nAttempting to compress.");
  193.             j = encode ( l,in_buf, cmp_buf);            /* Compress the data*/
  194.             printf("\nEncoder returned %u.",j);         /* Won't compress   */
  195.  
  196.             while (l--)
  197.             {
  198.                 in_buf = sav_ptr;
  199.                 printf("\nFilling the buffer with %u bytes.",l);
  200.                 for (i=0; i< l; i++)
  201.                 {
  202.                     *in_buf++ = *tick;
  203.                     j = 8;
  204.                     while (j--);                        /* Waste some time */
  205.                 }
  206.                 in_buf = sav_ptr;
  207. /*              show_hex(l,in_buf); */
  208.                 printf("\nCompressing,");
  209.                 j = encode ( l,in_buf, cmp_buf);
  210.                 printf(" returned %u.",j);
  211.   /*            show_hex(j,cmp_buf); */
  212.  
  213.                 in_buf = sav_ptr;
  214.                 printf("\nExpanding,");
  215.                 j = decode (j,cmp_buf,out_buf);
  216.  
  217.                 printf(" returned %u.",j);
  218.                 if (j != l)
  219.                     return(1);
  220.  
  221.                 printf("\nComparing,");
  222.                 k = memicmp (out_buf, in_buf,j);
  223.                 if (k)
  224.                 {
  225.                     printf(" did not compare!\n");
  226.                     return(1);
  227.                 }
  228.                 printf(" okay.");
  229.  
  230.                 printf("\nCalculating CRC.");       /* Calculate CRC    */
  231.                 k = calc_crc(SET_CRC,j,out_buf);
  232.                 printf("\nChecking CRC of %4.4X,",k);
  233.                 j = calc_crc(GET_CRC,j,out_buf);    /* Check CRC    */
  234.                 if (j)
  235.                 {
  236.                     printf(" bad CRC!\n");
  237.                     return(1);
  238.                 }
  239.                 printf(" okay.\n");
  240.  
  241.                 in_buf = sav_ptr;
  242.                 printf("\nFilling buffer with %u nulls.",l);
  243.                 for (i=0; i< l; i++)
  244.                     *in_buf++ = (byte) 0;
  245.  
  246.                 in_buf = sav_ptr;
  247.                 printf("\nCompressing,");
  248.                 j = encode ( l,in_buf, cmp_buf);
  249.                 printf(" returned %u.",j);
  250.  
  251.                 in_buf = sav_ptr;
  252.                 printf("\nExpanding,");
  253.                 j = decode (j,cmp_buf,out_buf);
  254.  
  255.                 printf(" returned %u.",j);
  256.                 if (j != l)
  257.                     return(1);
  258.  
  259.                 printf("\nComparing,");
  260.                 k = memicmp (out_buf, in_buf,j);
  261.                 if (k)
  262.                 {
  263.                     printf(" did not compare!");
  264.                     return(1);
  265.                 }
  266.                 printf(" okay.\n");
  267.             }
  268.         }
  269.     }
  270.     return 0;
  271.  
  272. }
  273. /* Dummy routine to keep the linker happy. */
  274.  
  275. void screen (short one, SYS *two)
  276. {
  277.     one = (short) two;
  278. }
  279.  
  280. void show_hex(word len, byte *string)
  281. {
  282.     word i;
  283.  
  284.     while (len)
  285.     {
  286.         i = 16;
  287.         while ( (len) && (i) )
  288.             {
  289.             printf("%2.2X ",*string++);
  290.             len --;
  291.             i--;
  292.             }
  293.  
  294.     printf("\n");
  295.     }
  296.     return;
  297. }
  298.